﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using BLL;
using BLL.RF.Repair;
using Model;
using Model.RF.Repair;

/// <summary>
///AirtightnessService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class AirtightnessService : System.Web.Services.WebService
{
    private Airtightness a;
    private ProductType p;
    private ProductType_Airtightness pa;
    private ProductType_Flow pf;
    private ClientSoft cs;
    private RepairLock rl;
    private ATEUser user;
    //public AuthHeaderGB sHeader;                //暂时不启用权限验证

    public AirtightnessService()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
        a = new Airtightness();
        p = new ProductType();
        pa = new ProductType_Airtightness();
        pf = new ProductType_Flow();
        cs = new ClientSoft();
        rl = new RepairLock();
        user = new ATEUser();
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod(Description = "判断气密自动化测试客户端软件的版本是否有效")]
    public bool IsValidAirtightnessClientSoft(string csVersion)
    {
        return !string.IsNullOrEmpty(cs.GetClientSoftbyNV("AirtightnessTest", csVersion).CSName);
    }

    [WebMethod(Description = "判断产品类型是否合法")]
    public bool IsValidProductTypeID(string productTypeID)
    {
        return !string.IsNullOrEmpty(p.LoadEntity(productTypeID).ProductTypeID);
    }

    [WebMethod(Description = "判断产品类型相应通道的气密信息是否登记")]
    public bool HasValidProductType_AirtightnessInfo(string productTypeID,int channelNO)
    {
        return !string.IsNullOrEmpty(pa.ProductType_Airtightness_GetbyPIDCHNO(productTypeID, channelNO).ProductTypeID);
    }

    [WebMethod(Description = "获取此产品类型气密信息中的规格值")]
    public ProductType_AirtightnessInfo GetSpecValuebyPID(string productTypeID, int channelNO)
    {
        return pa.ProductType_Airtightness_GetbyPIDCHNO(productTypeID, channelNO);
    }

    [WebMethod(Description = "判断之前工序是否有合格记录")]
    public bool ProductType_Flow_HasValidSevenStep(string productSN, string productTypeID)
    {
        return pf.ProductType_Flow_HasValidSevenStep(productSN, productTypeID, "AirtightnessStep");
    }

    [WebMethod(Description = "上传气密数据")]
    //[SoapHeader("sHeader")]
    public bool TestData_Upload(AirtightnessInfo ai)
    {
        //验证用户是否登陆
        //if (sHeader == null)
        //    return false;
        //if (!sHeader.AuthenticateUser(sHeader.Username, sHeader.Password))
        //    return false;
        return a.Insert(ai);
    }

    [WebMethod(Description = "根据序列号查询气密数据")]
    public List<AirtightnessInfo> GetAirtightness_bySN(string productSN)
    {
        return (List<AirtightnessInfo>)a.Airtightness_SelectbySN(productSN);
    }



    #region 20180125日，增加自动返修相关

    [WebMethod(Description = "测试不合格时，自动生成返修锁定，以限制重新走当前工序")]
    public bool RepairLock_AutoBuild(string productSN)
    {
        productSN = CommHelper.GetProductSN(productSN);
        RepairLockInfo rli = new RepairLockInfo() { ID = 0, ProductSN = productSN, RecordTime = DateTime.Now, StepItem = "AirtightnessStep", IsValid = true };
        return rl.RepairLock_AutoBuild(rli);
    }

    [WebMethod(Description = "测试前，判断序列号在功率测试工序是否被锁定")]
    public bool RepairLock_IsLock(string productSN)
    {
        productSN = CommHelper.GetProductSN(productSN);
        return rl.RepairLock_ProductSNIsLock(productSN, "AirtightnessStep");
    }
    #endregion



    #region 20180403日，增加测试录入工号管控

    [WebMethod(Description = "测试前校验录入工号，是否系统已经配置为“测试”的工号")]
    public bool IsValidUserID_forTest(string userID)
    {
        return user.ATEUser_IsValidForTest(userID);
    }
    #endregion


    #region 20180403日，增加判断ATE前工序是否有合格数据的检测，用于防止使用中兴矩阵开关测试软件时漏检前工序的风险

    [WebMethod(Description = "增加判断ATE前工序是否有合格数据的检测，用于防止使用中兴矩阵开关测试软件时漏检前工序的风险")]
    public bool ProductType_Flow_HasValidSevenStep_ForATEStep(string productSN, string productTypeID)
    {
        return pf.ProductType_Flow_HasValidSevenStep(productSN, productTypeID, "ATEStep");
    }
    #endregion
}

